package com.lzx.study.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import reactor.core.publisher.Flux;

import java.util.function.Consumer;

import static org.springframework.ai.chat.memory.ChatMemory.CONVERSATION_ID;

@Controller
public class ChatMemory4RedisController {
    @Resource(name = "qwenChatClient")
    private ChatClient qwenChatClient;
    @GetMapping("/chatmemory/chat")
    public Flux<String> chat(String msg,String userId){
        Flux<String> content = qwenChatClient.prompt(msg)
                .advisors(advisorSpec -> advisorSpec.param(CONVERSATION_ID, userId)).stream().content();
        System.out.println("content = " + content);
        return content;
    };
}
